/*
* ============================================================================
*  Name        : example_006.hxx
*  Part of     : Finite state machine examples
*  Description : State machine body.
*              :    In Main state, machine listens for user key presses.
*              :  When 'right' move is detected in goes to MoveRight state, executes the move
*              :  and waits for move 'left' command - the only accepted move/event in this state.
*              :    The same scenario with valid in opposite direction when 'left' key is 
*              :  pressed in the Main state.
*              :    Wrong moves are counted and if the number exceeds the limit,
*              :  state machine exists
*              :  
*  Version     : %version: %
*
* ============================================================================
*/

/**
    @code
    SM_DECLARE
    (
        Embedded_src,
        Embedded
        async
        {
            Exceptions
            {
                // Key presses must be processed in all states,
                // so putting it in the exceptions is a good idea
                Ev_Ext_UserKey          process_key_press       nojump

                // In case framework wants to terminate
                Ev_Sys_Terminate        good_bye                nojump
                Ev_Sys_Terminate        exit                    nojump
                
                // Exception gets wrong moves
                Ev_Int_MoveRight        wrong_move              nojump
                Ev_Int_MoveLeft         wrong_move              nojump
                
                // Wrong key is treated as wrong move
                Ev_Int_WrongKey         unknown_key             nojump
                Ev_Int_WrongKey         wrong_move              nojump
            }
            Main
            {
                Ev_Int_MoveRight        null                    MoveRight
                Ev_Int_MoveLeft         null                    MoveLeft
            }
            MoveRight
            {
                Ev_Sys_OnEntry          on_right_move           nojump
                Ev_Int_MoveLeft         null                    MoveLeft
            }
            MoveLeft
            {
                Ev_Sys_OnEntry          on_left_move            nojump
                Ev_Int_MoveRight        null                    MoveRight
            }
        } 
    );
    @endcode
 */

SM_DECLARE
(
    Embedded_src,
    Embedded
    async
    {
        Exceptions
        {
            // Key presses must be processed in all states,
            // so putting it in the exceptions is a good idea
            Ev_Ext_UserKey          process_key_press       nojump

            // In case framework wants to terminate
            Ev_Sys_Terminate        good_bye                nojump
            Ev_Sys_Terminate        exit                    nojump
            
            // Exception gets wrong moves
            Ev_Int_MoveRight        wrong_move              nojump
            Ev_Int_MoveLeft         wrong_move              nojump
            
            // Wrong key is treated as wrong move
            Ev_Int_WrongKey         unknown_key             nojump
            Ev_Int_WrongKey         wrong_move              nojump
        }
        Main
        {
            Ev_Int_MoveRight        null                    MoveRight
            Ev_Int_MoveLeft         null                    MoveLeft
        }
        MoveRight
        {
            Ev_Sys_OnEntry          on_right_move           nojump
            Ev_Int_MoveLeft         null                    MoveLeft
        }
        MoveLeft
        {
            Ev_Sys_OnEntry          on_left_move            nojump
            Ev_Int_MoveRight        null                    MoveRight
        }
    } 
);

